package com.aacar.utils;

import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * <br/>
 *
 * @author: Gongle
 * Date: 2015/7/12
 * Time: 20:44
 */
@XmlRootElement(name = "result")
public class ActionResult implements Serializable {
    private Boolean success;
    private Integer code;
    private String msg;
    private Map attributes = new HashMap();


    /**
     * 操作完成，返回状态信息
     *
     * @param message
     * @return this 当前对象实例,可继续使用其它API, 链式操作.
     */

    public static ActionResult success(String message) {
        ActionResult result = new ActionResult();
        result.setSuccess(Boolean.valueOf(true));
        result.setMsg(message);
        return result;
    }

    /**
     * 获得失败的操作结果
     *
     * @param message
     * @return this 当前对象实例,可继续使用其它API, 链式操作.
     */

    public static ActionResult failure(String message) {
        ActionResult result = new ActionResult();
        result.setSuccess(Boolean.FALSE);
        result.setMsg(message);
        return result;
    }


    public ActionResult addAttribute(String key, Object val) {
        this.attributes.put(key, val);
        return this;
    }


    public Map getAttributes() {
        return this.attributes;
    }

    public void setAttributes(Map attributes) {
        this.attributes = attributes;
    }

    public String getMsg() {
        return this.msg;
    }

    public ActionResult setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public Boolean getSuccess() {
        return this.success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

}
